package com.zd.service.impl;

import java.util.List;

import com.zd.dao.NovelDao;
import com.zd.dao.UserDao;
import com.zd.dao.impl.NovelDaoImpl;
import com.zd.dao.impl.UserDaoImpl;
import com.zd.entity.Chapter;
import com.zd.entity.LBVipBook;
import com.zd.entity.Novel;
import com.zd.entity.NovelWriterType;
import com.zd.entity.PageBean;
import com.zd.entity.User;
import com.zd.service.NovelService;

public class NovelServiceImpl implements NovelService {
	NovelDao novelDaoImpl=new NovelDaoImpl();
	@Override
	public List<String> novelType() {
		// TODO Auto-generated method stub
		List<String> typeList=novelDaoImpl.novelType();
		return typeList;
	}
	@Override
	public List<String[]> type_NovelName() {
		// TODO Auto-generated method stub
		List<String[]> typeList=novelDaoImpl.type_NovelName();
		return typeList;
	}
	@Override
	public List<Novel> novelHitsSelect() {
		// TODO Auto-generated method stub
		List<Novel> typeList=novelDaoImpl.novelHitsSelect();
		return typeList;
	}
	@Override
	public List<NovelWriterType> novelVipSelect() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.novelVipSelect();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectNewNovelList() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectNewNovelList();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectNewNovelListMore() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectNewNovelListMore();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectNewNovelListMoreTen() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectNewNovelListMoreTen();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectEndNovelListone() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectEndNovelListone();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectEndNovelListmore() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectEndNovelListmore();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectEndNovelListten() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectEndNovelListten();
		return typeList;
	}
	@Override
	public List<NovelWriterType> SelectnovelN() {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.SelectnovelN();
		return typeList;
	}
	@Override
	public List<Chapter> selectNoveChapter() {
		// TODO Auto-generated method stub
		List<Chapter> typeList=novelDaoImpl.selectNoveChapter();
		return typeList;
	}
	@Override
	public List<Chapter> selectshuChapter(String novelId) {
		// TODO Auto-generated method stub
		List<Chapter> typeList=novelDaoImpl.selectshuChapter(novelId);
		return typeList;
	}
	@Override
	public List<NovelWriterType> selectnovelById(String novelId) {
		// TODO Auto-generated method stub
		List<NovelWriterType> typeList=novelDaoImpl.selectnovelById(novelId);
		return typeList;
	}
	@Override
	public int selectChapterNum(String string) {
		// TODO Auto-generated method stub
			int num=novelDaoImpl.selectChapterNum(string);
			return num;
	}
	@Override
	public Chapter selectNowChapter(String novelId) {
		// TODO Auto-generated method stub
		Chapter chapter=novelDaoImpl.selectNowChapter(novelId);
		return chapter;
	}
	@Override
	public PageBean<Novel> selectNovel(int aPageNum, int nowPage) {
		// TODO Auto-generated method stub
		PageBean<Novel> pageBean= new PageBean<Novel>();
		NovelDao novelDaoImpl = new NovelDaoImpl();
		int count=novelDaoImpl.getInforAllNum();
		int pageNumEnd=count%aPageNum==0?count/aPageNum:count/aPageNum+1;
		nowPage=nowPage<1?1:nowPage;
		nowPage=nowPage>pageNumEnd?pageNumEnd:nowPage;
		
		List<Novel> userList= novelDaoImpl.selectNovelLimit((nowPage-1)*aPageNum,aPageNum);
//		List<User> userList=this.selectUserLimit(((nowPage-1)*aPageNum), aPageNum);
		pageBean.setaPageNum(aPageNum);
		pageBean.setCount(count);
		pageBean.setNowPage(nowPage);
		pageBean.setPageNumEnd(pageNumEnd);
		pageBean.setDate(userList);
		return pageBean;
		
	}
	@Override
	public int selectTypeis(String novelType1) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.selectByTypeName(novelType1);
		System.out.println("让我看看"+num);
		if(num==0) {
			System.out.println("他执行添加type了");
			novelDaoImpl.addNovelType(novelType1);
			//加入后再次查找
			num=novelDaoImpl.selectByTypeName(novelType1);
		}
		return num;
	}
	@Override
	public int selectWriteris(String writerName) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.selectByWriterName(writerName);
		
		if(num==0) {
			novelDaoImpl.addWriter(writerName);
			//加入后再次查找
			num=novelDaoImpl.selectByWriterName(writerName);
		}
		return num;
	}
	@Override
	public int updateNovel(Novel novel, int novelTypeId, int writerId) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.updateNovel(novel,novelTypeId,writerId);
		return num;
	}
	@Override
	public int deleteNovel(int novelId) {
		// TODO Auto-generated method stub
//		String in=novelDaoImpl.selectChapterByNovelId(novelId);
//		System.out.println(in);
//		if(!"".equals(in)) {
//			String ChapterIds = in.substring(0, in.length() - 1);
			//执行删除章节 返回删除了多少条数据
//			System.out.println(ChapterIds);
			int num =novelDaoImpl.deleteChapterByIds(novelId);
//			System.out.println(num);
//		}
			int c=novelDaoImpl.deleteReadHistory(novelId);
			int n= novelDaoImpl.deleteNovelByNovelId(novelId);
			return n;
		
		
		//删完chapter章节再删除小说
		
		
		
	}
	@Override
	public int addNovel(Novel novel, int novelTypeId, int writerId) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.addNovel(novel,novelTypeId,writerId);
		return num;
	}
	@Override
	public PageBean<Novel> sousuoSelectUser(int aPageNum, int nowPage, String sousuo) {
		// TODO Auto-generated method stub
		PageBean<Novel> pageBean= new PageBean<Novel>();
		UserDao userDaoImpl = new UserDaoImpl();
		int count=NovelDaoImpl.getSousuoInforAllNum(sousuo);
		int pageNumEnd=count%aPageNum==0?count/aPageNum:count/aPageNum+1;
		nowPage=nowPage<1?1:nowPage;
		nowPage=nowPage>pageNumEnd?pageNumEnd:nowPage;
		
		List<Novel> userList= NovelDaoImpl.sousuoSelectUserLimit((nowPage-1)*aPageNum,aPageNum,sousuo);
//		List<User> userList=this.selectUserLimit(((nowPage-1)*aPageNum), aPageNum);
		pageBean.setaPageNum(aPageNum);
		pageBean.setCount(count);
		pageBean.setNowPage(nowPage);
		pageBean.setPageNumEnd(pageNumEnd);
		pageBean.setDate(userList);
		return pageBean;
	}
	@Override
	public int addRead(int userId, String novelId) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.addRead(userId,novelId);
		return num;
	}
	@Override
	public List<Novel> selectVIP() {
		// TODO Auto-generated method stub
		List<Novel> lb=novelDaoImpl.selectVIP();
		return lb;
	}
	@Override
	public List<LBVipBook> selectVipBook() {
		// TODO Auto-generated method stub
		List<LBVipBook> lb=novelDaoImpl.selectVIPBook();
		return lb;
	}
	@Override
	public int updateVIPBook(String novelId, String vipBookId) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.updateVIPBook(novelId,vipBookId);
		return num;
	}
	@Override
	public int addHits(String novelId) {
		// TODO Auto-generated method stub
		int num=novelDaoImpl.addHits(novelId);
		return num;
	}
	@Override
	public List<Novel> selectNovelaudit() {
		// TODO Auto-generated method stub
		List<Novel> list=novelDaoImpl.selectNovelaudit();
		return list;
	}
	@Override
	public List<Chapter> selectChapteraudit() {
		// TODO Auto-generated method stub
		List<Chapter> list=novelDaoImpl.selectChapteraudit();
		return list;
	}

}
